package com.donleo.mybatis.controller;

import com.donleo.mybatis.common.CommonResult;
import com.donleo.mybatis.model.Dept;
import com.donleo.mybatis.service.IDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author liangd
 * date 2020-12-03 11:08
 * code
 */
@Api(tags = "部门管理")
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Resource
    private IDeptService deptService;


    @ApiOperation("添加部门")
    @PostMapping("/add")
    public CommonResult add(@RequestBody Dept dept){
        Integer id = deptService.add(dept);
        return CommonResult.success(id);
    }

    @ApiOperation("删除部门")
    @DeleteMapping("/delete")
    public CommonResult delete(Integer id){
        Integer count = deptService.delete(id);
        return CommonResult.success(count);
    }

    @ApiOperation("修改部门")
    @PutMapping("/update")
    public CommonResult update(@RequestBody Dept dept){
        Integer count = deptService.update(dept);
        return CommonResult.success(count);
    }

    @ApiOperation("根据主键Id查询单个1 --?")
    @GetMapping("/findById1")
    public CommonResult findById1(@RequestParam Integer id){
        Dept dept = deptService.findById(id);
        return CommonResult.success(dept);
    }

    @ApiOperation("根据主键Id查询单个2 --/")
    @GetMapping("/findById2/{id}")
    public CommonResult findById2(@PathVariable("id") Integer id){
        Dept dept = deptService.findById(id);
        return CommonResult.success(dept);
    }

    @ApiOperation("部门列表")
    @GetMapping("/findAll")
    public CommonResult findAll(){
        return deptService.findAll();
    }
}
